package org.vt.ece3574.pictoslider;

import android.graphics.Bitmap;

/**
 * This class represents a high score. It contains a long to represent the time
 * it took to solve a puzzle, and a bitmap to represent the image used in the
 * puzzle.
 * 
 * @author Michael
 * 
 */
public class HighScoreObject implements Comparable<HighScoreObject> {

	/**
	 * The time it took to solve the puzzle.
	 */
	private long time;
	/**
	 * The image used in the puzzle solved.
	 */
	private Bitmap image;
	/**
	 * The number of moves it took to solve the puzzle.
	 */
	private int moves;
	/**
	 * True if this HighScoreObject should be compared by its number of moves
	 * and not its time.
	 */
	private boolean byMoves = false;

	/**
	 * @return The number of moves it took to solve the puzzle.
	 */
	public int getMoves() {
		return moves;
	}

	/**
	 * @param moves
	 *            - The number of moves it took to solve the puzzle
	 */
	public void setMoves(int moves) {
		this.moves = moves;
	}

	/**
	 * @param b
	 *            - True if this object should be sorted by number of moves,
	 *            False if it should be sorted by time.
	 */
	public void sortByMoves(boolean b) {
		byMoves = b;
	}

	/**
	 * @return The time it took to solve the puzzle.
	 */
	public long getTime() {
		return time;
	}

	/**
	 * @param time
	 *            - The time it took to solve the puzzle.
	 */
	public void setTime(long time) {
		this.time = time;
	}

	/**
	 * @return The image used in the puzzle.
	 */
	public Bitmap getImage() {
		return image;
	}

	/**
	 * @param image
	 *            - The image used in the puzzle.
	 */
	public void setImage(Bitmap image) {
		this.image = image;
	}

	/**
	 * Only constructor for this class.
	 * 
	 * @param t
	 *            - The time it took to solve the puzzle.
	 * @param b
	 *            - The image used in the puzzle.
	 */
	public HighScoreObject(int m, long t, Bitmap b) {
		time = t;
		image = b;
		moves = m;
	}

	/**
	 * @return The time it took to solve the puzzle as a String with the format
	 *         MM:SS, with zeros if necessary.
	 */
	public String getTimeAsString() {
		int seconds = (int) (time / 1000);
		int minutes = seconds / 60;
		seconds = seconds % 60;
		String mins = minutes + "";
		String secs = seconds + "";
		if (minutes < 10) {
			mins = "0" + mins;
		}
		if (seconds < 10) {
			secs = "0" + secs;
		}
		return mins + ":" + secs;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	public int compareTo(HighScoreObject another) {
		if (byMoves) {
			return (this.getMoves() - another.getMoves());
		}
		return (int) (this.getTime() - another.getTime());
	}

}
